package com.atcumt.alibaba;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

/* 
 * 5 2
 * 1 4 2 3 5
 * 
 * 3
 */
public class Main02 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        Arrays.sort(nums);
        int max = nums[n - 1];

        int res = 0;
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            while (Math.abs(nums[i] - max) >= k) {
                nums[i] = nums[i] + k;
            }
        }
        for (int i = 0; i < nums.length; i++) {
            hashMap.put(nums[i], hashMap.getOrDefault(nums[i], 0) + 1);
            res = Math.max(res, hashMap.get(nums[i]));
        }
        // for (int i = n -1; i >=0; i--) {
        //     int count = 1;
        //     for (int j = i -1; j >=0; j--) {
        //         // int max = Integer.MIN_VALUE;
        //         if ((nums[j] - nums[i]) % k == 0) {
        //             count++;
        //         }
        //     }
        //     res = Math.max(res, count);
        // }
        System.out.println(res);

    }
}
